"""
角色模型（对应现有 mx_role 表）
"""
from datetime import datetime
from app import db


class Role(db.Model):
    """角色表（对应现有 mx_role 表，用于后台菜单权限控制）"""
    __tablename__ = 'mx_role'
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False, comment='角色名字')
    create_time = db.Column(db.DateTime, default=datetime.utcnow, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment='更新时间')
    
    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'create_time': self.create_time.isoformat() if self.create_time else None,
            'update_time': self.update_time.isoformat() if self.update_time else None
        }
